package cn.hls.web.controller.dict;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.hls.entity.Role;
import cn.hls.entity.vo.Msg;
import cn.hls.entity.vo.PageInfo;
import cn.hls.service.RoleService;
import cn.hls.web.controller.base.BaseController;

/**
 * @fileName: RoleController.java
 * @package: com.bangni.web.controller.dict
 * @Description: 角色Controller控制类
 * @author: yinghui.zhang
 * @email: uuhui@163.com
 * @date: 2015-5-2
 */
@Controller
@RequestMapping("/role")
public class RoleController extends BaseController<Role> {
	@Resource(name = "roleService")
	private RoleService roleSerivce;

	@RequestMapping("/add")
	@ResponseBody
	public Msg add(Role entity) throws Exception {
		 
		boolean flag = roleSerivce.add(entity);
		if (!flag) {
			msg.setStatus(201);
			msg.setInfo("操作失败");
		}else{
			msg.setInfo("操作成功");
			msg.setStatus(200);
		}
		return msg;
	}

	@ResponseBody
	@RequestMapping("/list")
	public PageInfo<Role> list(PageInfo<Role> page, Role entity)
			throws Exception {
		return roleSerivce.loadRoleInfo(entity, page);
	}

	@RequestMapping("/del")
	@ResponseBody
	public Msg del(Long id) throws Exception {
		boolean flag = false;
		flag = roleSerivce.deleteRole(id);
		if (flag) {
			msg.setStatus(200);
			msg.setInfo("操作成功");
		} else {
			msg.setStatus(201);
			msg.setInfo("操作失败");
		}
		msg.setInfo("删除成功");
		msg.setStatus(200);
		return msg;
	}

	@RequestMapping("/view")
	public String view() throws Exception {
		return "/dict/role";
	}

	@RequestMapping("/update")
	@ResponseBody
	public Msg update(Role entity) throws Exception {
		boolean flag = roleSerivce.update(entity);
		if (!flag) {
			msg.setStatus(201);
			msg.setInfo("操作失败");
		}else{
			msg.setStatus(200);
			msg.setInfo("会员设置成功");
		}
		return msg;
	}
}
